#region Microsoft Public License
/*
 * (c) Copyright Chenjun Wu. http://utablesdk.codeplex.com
 * 
 * This source is subject to the Microsoft Public License (Ms-PL).
 * Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
 * All other rights reserved.
 */
#endregion

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using UTable.Input;
using UTable.Input.MultiTouch;
using UTable.Objects;
using UTable.Objects.Controls;
using System.IO;

namespace UTable.Objects
{
    /// <summary>
    /// Interaction logic for USaveFileDialog.xaml
    /// </summary>
    public partial class USaveFileDialog : UObject
    {
        public USaveFileDialog()
        {
            InitializeComponent();
        }

        private USaveFileDialogModel model = new USaveFileDialogModel();

        public override object GetModel()
        {
            return model;
        }

        public override void InitializeModel(object model)
        {
            if (model is USaveFileDialogModel)
            {
                this.model = model as USaveFileDialogModel;
                this.FileNameBox.Text = this.model.SaveFileName;
            }
        }

        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            model.ShouldSave = true;
            model.SaveFilePath = System.IO.Path.Combine(Explorer.DirectoryPath, FileNameBox.Text);
            Close();
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            model.ShouldSave = false;
            Close();
        }
    }

    public class USaveFileDialogModel
    {
        public Boolean ShouldSave = false;

        public String SaveFileDirectory = String.Empty;

        public String SaveFileName = string.Empty;

        public String SaveFilePath
        {
            get
            {
                return Path.Combine(SaveFileDirectory, SaveFileName);
            }
            set
            {
                SaveFileDirectory = Path.GetDirectoryName(value);
                SaveFileName = Path.GetFileName(value);
            }
        }
    }
}
